/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import controller.PfadErsteller;
import controller.TreeSceneErsteller;
import controller.TreeSceneErstellerRegel;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import model.Baum;
import model.Kante;
import model.Knoten;
import model.Pfad;
import model.Tabelle;
import org.netbeans.api.visual.graph.GraphScene;
import org.netbeans.api.visual.graph.layout.GraphLayout;
import org.netbeans.api.visual.graph.layout.GraphLayoutFactory;
import org.netbeans.api.visual.graph.layout.GraphLayoutSupport;
import org.netbeans.api.visual.layout.LayoutFactory;
import org.netbeans.api.visual.layout.SceneLayout;
import org.netbeans.api.visual.widget.Scene;

/**
 *
 * @author Anne
 */


public class Regelansicht extends javax.swing.JFrame {

    private JFrame frame;
    
    private Baum baum;
    
    private String[] data;
    
    private TreeSceneErstellerRegel scene;
    
    private Tabelle tabelle;
    
    private Pfad pfad;
    
    private Tabellenansicht parentFrame;
    /**
     * Creates new form Regelansicht
     */
    public Regelansicht(String[] data, Baum baum, Tabelle tabelle) {
        frame= this;
        this.data = data;
        this.baum = baum;
        this.tabelle = tabelle;
        PfadErsteller ersteller = new PfadErsteller(baum, tabelle);
        this.pfad = ersteller.createPfad(data);
        initComponents();
        scene = createScene();
        layoutScene_NetbeansStyle(scene, scene.getWurzel());
        showScene(scene, "Using NetBeans GraphLayout");
        this.setSize(500, 400);
        this.setVisible(true);
        this.setTitle("Regeldarstellung");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jBTabelle = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel2.setBackground(new java.awt.Color(153, 255, 153));
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jBTabelle.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N
        jBTabelle.setText("zurück zur Tabellenansicht");
        jBTabelle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBTabelle.setPreferredSize(new java.awt.Dimension(190, 50));
        jBTabelle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTabelleActionPerformed(evt);
            }
        });
        jPanel2.add(jBTabelle);

        jButton1.setText("Regel als Text");
        jButton1.setPreferredSize(new java.awt.Dimension(190, 50));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1);

        getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    //Actionlistener Zum Wechseln in die Tabellenansicht
    private void jBTabelleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTabelleActionPerformed
        //Tabellenansicht tabellenAnsicht = new Tabellenansicht();
        parentFrame.setVisible(true);
        frame.dispose();
    }//GEN-LAST:event_jBTabelleActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        RegelAlsText alsText = new RegelAlsText(pfad);
        alsText.setVisible(true);
        alsText.setSize(300, 300);
        alsText.setAlwaysOnTop(true);
    }//GEN-LAST:event_jButton1ActionPerformed

   public JFrame getFrame() {
        return frame;
    }

  
    public void setFrame(JFrame frame) {
        this.frame = frame;
    } 
    
    public void lesenDerZeilenDerTabelle(){
    
    
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBTabelle;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
 private void showScene(TreeSceneErstellerRegel scene, String title) {
        JScrollPane panel = new JScrollPane(scene.createView());
        this.add(panel, BorderLayout.CENTER);
    }

    private void layoutScene_NetbeansStyle(
            GraphScene<Knoten, Kante> scene, Knoten root) {
        GraphLayout<Knoten, Kante> graphLayout = GraphLayoutFactory
                .createTreeGraphLayout(100, 100, 50, 50, true);
        GraphLayoutSupport.setTreeGraphLayoutRootNode(graphLayout, root);
        SceneLayout sceneLayout = LayoutFactory.createSceneGraphLayout(scene,
                graphLayout);
        sceneLayout.invokeLayoutImmediately();
    }

    private TreeSceneErstellerRegel createScene() {
        TreeSceneErstellerRegel sceneTemp = new TreeSceneErstellerRegel(baum, pfad);
        return sceneTemp;
    }

    /**
     * @param parentFrame the parentFrame to set
     */
    public void setParentFrame(Tabellenansicht parentFrame) {
        this.parentFrame = parentFrame;
    }
}


